<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录</title>
    <script src="../lib/js/jquery-1.10.1.min.js"></script>
    <script src="../lib/swiper/js/swiper.min.js"></script>
    <script src="../lib/bootstrap/js/bootstrap.min.js"></script>
    <script src="../lib/layui/layui.js"></script>
    <script src="../ajax/request.js"></script>
    <script src="../utils/cookie.js"></script>
    <script src="../utils/common.js"></script>
    <link rel="stylesheet" href="../lib/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="../lib/swiper/css/swiper.min.css">
    <link rel="stylesheet" href="../lib/layui/css/layui.css">
    <link rel="stylesheet" href="../styles/css/index.css">


    <!-- 自己的样式  -->
    <link rel="stylesheet" href="../styles/css/register.css">

    <script>
        // $(".register").hide();
        // $(function(){
        //     $("#common").load("./common.html",function(data){
        //         console.log(data);
        //         console.log("success")
        //         $(".register").show();
        //     })
        // })
    </script>
</head>
<body>
    <div class="" id="common"></div>
    <div class="register">
        <form class="form layui-form layui-form-pane">
            <h3 class="title">千锋在线商城</h3>
            <p class="text" >欢迎登录</p>
            <div class="form-box">
                <div class="layui-form-item inputitem">
                    <label class="layui-form-label">账号</label>
                    <div class="layui-input-inline">
                      <input type="text" id="account" name="account" lay-verify="required" lay-reqtext="账号是必填项，岂能为空？"   placeholder="请输入手机号/邮箱/用户名"  autocomplete="off" class="layui-input">
                    </div>
                    <!-- <div class="layui-form-mid layui-word-aux">请务必填写用户名</div> -->
                </div>
                <div class="layui-form-item inputitem">
                    <label class="layui-form-label">密码</label>
                    <div class="layui-input-inline">
                      <input type="password" id="pass" name="password" lay-verify="required|pass" lay-reqtext="请填写6到12位密码" placeholder="请输入密码" autocomplete="off" class="layui-input">
                    </div>
                    <!-- <div class="layui-form-mid layui-word-aux">请填写6到12位密码</div> -->
                </div>

                <div class="layui-form-item inputitem">
                    <button type="button"  lay-submit="" lay-filter="demo1" class="loginbtn layui-btn layui-btn-normal layui-btn-fluid">登录</button>
                </div>

                <div class="linkitem inputitem">
                    <a class="link pass" href="./forgetpass.html">忘记密码</a>
                    <a class="link" href="./register.html">立即注册</a>
                </div>
            </div>
        </form>
    </div>

    <script>

        $(function(){

            var url = urlParse()
            console.log(url)
            if(url.user){
                $("#account").val(url.user);
            }

            $(".loginbtn").on("click",function(){
                loginaction()
            })

            async function loginaction(){
                var account = $("#account").val()
                var pass = $("#pass").val();
                console.log(account,pass)
                if(account && pass){
                    // ajax 
                    let res = await login_ajax({account,pass})
                    const {status,user,detail}  = res;
                    if(status){
                        setCookie("useraccount",user,30);
                        if(url.from){
                            if(url.from="gooddetail"){
                                history.back()
                            }
                        }else{
                            location.href = "./index.html"
                        }
                    }else{
                        delCookie("useraccount");
                    }
                    layer.msg(detail)
                    
                }else{
                    // layer.alert("请先输入账号或者密码")
                }
            }


            $(window).keydown(function(event){
                var event =  event || window.event;
                if(event.keyCode==13){
                    loginaction()
                }
            });

        })

    </script>
</body>
</html>